﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingIsMyPassion.Coding.Test
{
    [TestClass()]
    public class SortRotateFindTest
    {
        SortRotateFind mysortandFind;

        public SortRotateFindTest()
        {
            mysortandFind = new SortRotateFind();

        }
        [TestMethod()]
        public void FindMinValueDefaultTest()
        {
            //Arrange
            int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            int expected = 1;
            //Act
            int actual = mysortandFind.Min(array);
            //Assert
            Assert.IsTrue(actual == expected);
        }

        [TestMethod()]
        public void FindMinValueRotation_1_Test()
        {
            //Arrange
            int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            int expected = 1;
            //Act
            mysortandFind.Rotate(ref array);
            int actual = mysortandFind.Min(array);
            //Assert
            Assert.IsTrue(actual == expected);
        }

        [TestMethod()]
        public void FindMinValueRotation_2_Test()
        {
            //Arrange
            int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            int expected = 1;
            //Act
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            int actual = mysortandFind.Min(array);
            //Assert
            Assert.IsTrue(actual == expected);
        }

        [TestMethod()]
        public void FindMinValueRotation_3_Test()
        {
            //Arrange
            int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            int expected = 1;
            //Act
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            int actual = mysortandFind.Min(array);
            //Assert
            Assert.IsTrue(actual == expected);
        }

        [TestMethod()]
        public void FindMinValueRotation_4_Test()
        {
            //Arrange
            int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            int expected = 1;
            //Act
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            int actual = mysortandFind.Min(array);
            //Assert
            Assert.IsTrue(actual == expected);
        }

        [TestMethod()]
        public void FindMinValueRotation_5_Test()
        {
            //Arrange
            int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            int expected = 1;
            //Act
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            int actual = mysortandFind.Min(array);
            //Assert
            Assert.IsTrue(actual == expected);
        }

        [TestMethod()]
        public void FindMinValueRotation_6_Test()
        {
            //Arrange
            int[] array = new int[] { 1, 2, 3, 4, 5, 6, 7 };
            int expected = 1;
            //Act
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            int actual = mysortandFind.Min(array);
            //Assert
            Assert.IsTrue(actual == expected);
        }

        [TestMethod()]
        public void FindMinValueRotation_dublicate_1_Test()
        {
            //Arrange
            int[] array = new int[] { 1, 2, 3, 4, 4, 4, 5, 6, 7 };
            int expected = 1;
            //Act
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            int actual = mysortandFind.Min(array);
            //Assert
            Assert.IsTrue(actual == expected);
        }

        [TestMethod()]
        public void FindMinValueRotation_dublicate_2_Test()
        {
            //Arrange
            int[] array = new int[] { 1, 1, 1, 2, 3, 4, 4, 4, 5, 6, 7 };
            int expected = 1;
            //Act
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            mysortandFind.Rotate(ref array);
            int actual = mysortandFind.Min(array);
            //Assert
            Assert.IsTrue(actual == expected);
        }

        [TestMethod()]
        public void FindMinValueRotation_dublicate_3_Test()
        {
            //Arrange
            int[] array = new int[] { 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7 };
            int expected = 1;
            //Act
            for (int i = 0; i < 50; i++)
            {
                mysortandFind.Rotate(ref array);
            }
            mysortandFind.Rotate(ref array);

            int actual = mysortandFind.Min(array);
            //Assert
            Assert.IsTrue(actual == expected);
        }
    }
}
